const express = require("express");
const router = express.Router();

// 导入控制器
const GoodsController = require("../controller/GoodsController");
const goodsController = new GoodsController(); // 实例化

// 引入权限检查中间件
const checkRoleMiddleware = require("../middleware/checkRoleMiddleware");

// 定义食材模块不同操作所需角色列表
const GOODS_ROLES = {
  CREATE: [1], // 新增：超管
  READ: [1, 2, 3], // 查询：所有登录用户
  UPDATE: [1], // 修改：超管
  DELETE: [1], // 删除：超管
};

// 食材管理路由

// 获取食材列表
router.get("/", (req, res) => {
  return goodsController.getGoodsList(req, res);
});

// 获取商品分类列表
router.get("/categories", (req, res) => {
  return goodsController.getGoodsCategories(req, res);
});

// 获取供应商列表
router.get("/suppliers", (req, res) => {
  return goodsController.getGoodsSuppliers(req, res);
});

// 获取食材详情
router.get("/:id", checkRoleMiddleware(GOODS_ROLES.READ), (req, res) => {
  return goodsController.getGoodsDetail(req, res);
});

// 新增食材
router.post("/", checkRoleMiddleware(GOODS_ROLES.CREATE), (req, res) => {
  return goodsController.createGoods(req, res);
});

// 更新食材信息
router.put("/:id", checkRoleMiddleware(GOODS_ROLES.UPDATE), (req, res) => {
  return goodsController.updateGoods(req, res);
});

// 停用食材 (软删除)
router.delete("/:id", checkRoleMiddleware(GOODS_ROLES.DELETE), (req, res) => {
  return goodsController.deactivateGoods(req, res);
});

module.exports = router;
